package sync;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.zip.CRC32;

public class ChecksumCRC32 {
	
	private static long createChecksum(String filename) throws Exception {
		
		byte[] buffer = new byte[1024];
		CRC32 ad = new CRC32();
		InputStream in = new FileInputStream(filename);
		int numRead;
		
		do {
			numRead = in.read(buffer);
			if(numRead > 0) {
				ad.update(buffer, 0, numRead);
			}
		} while(numRead != -1);

		in.close();
		return ad.getValue();
	}
	
	public static String getChecksum(String filename) throws Exception {
		
		long bytesum = createChecksum(filename);
		String checksum = "";
		checksum=Long.toString(bytesum);
		
		return checksum;
	}
}